package hello.controller;

import hello.model.HelloBean;

import java.util.Date;

import hello.service.MyMsgProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author majinding888@foxmail.com
 * @date 2016-12-21 上午10:43:48
 */
@Controller
public class HelloController {

    @Autowired
    MyMsgProducer myMsgProducer;

    @RequestMapping("/kafka/send")
    public String hello(String topic, String msg, Model model) {
        myMsgProducer.send(topic, msg);

        model.addAttribute("msg", "发送成功");
        return "hello";
    }

    @RequestMapping("/hello")
    public String hello(Model model) {
        model.addAttribute("msg", "你好!");
        return "hello";
    }

    @RequestMapping("/hello/json")
    @ResponseBody
    public Object helloBean() {
        HelloBean hello = new HelloBean();
        hello.setId(123);
        hello.setMsg("你好!");
        hello.setDate(new Date());
        return hello;
    }
}
